import 'dart:convert';
import 'package:meta/meta.dart';

class Message{
  final String name;
  final String avatar;
  final String company;
  final String position;
  final String msg;
  final String time;

  Message({
    @required this.name,
    @required this.avatar,
    @required this.company,
    @required this.position,
    @required this.msg,
    @required this.time,

  });

//  json 数据转换
   static List<Message> fromJson(String json){
     List<Message> _msgs = [];
     JsonDecoder decoder = new JsonDecoder();
     var mapdata = decoder.convert(json)['list'];
     mapdata.forEach((obj){
       Message message = new Message(
         name: obj['name'],
         avatar: obj['avatar'],
         company: obj['company'],
         position: obj['position'],
         msg: obj['msg'],
         time: obj['time']
       );
       _msgs.add(message);
     });
     return _msgs;
   }
}